<?php TPL::output('global/header.tpl.htm'); ?>

<div class="aw-container-wrap">
	<div class="container aw-publish">
		<div class="row">
			<div class="aw-content-wrap clearfix">
				<div class="col-sm-12 col-md-9 aw-main-content">
					<!-- tab 切换 -->
					<ul class="nav nav-tabs aw-nav-tabs active">
						<?php if (check_extension_package('project') && get_setting('project_enabled') == 'Y' && $this->user_info['permission']['publish_project']) { ?>
						<li><a href="project/publish/"><?php _e('活动'); ?></a></li>
						<?php } ?>
						<?php if (check_extension_package('ticket') && get_setting('ticket_enabled') == 'Y' && $this->user_info['permission']['publish_ticket']) { ?>
						<li><a href="ticket/publish/"><?php _e('工单'); ?></a></li>
						<?php } ?>
						<?php if ($this->user_info['permission']['publish_article']) { ?>
						<?php if (is_website()) { ?>
						<li><a href="publish/suggest/"><?php _e('建议'); ?></a></li>
						<?php } ?>
						<?php if(!$_GET['category']):?>
						<li><a href="publish/article/"><?php _e('文章'); ?></a></li>
						<?php endif;?>
						
						<?php } ?>
						<?php if(!$_GET['category']):?>
						<li class="active"><a href="publish/"><?php _e('问题'); ?></a></li>
						<h2 class="hidden-xs"><i class="icon icon-ask"></i> <?php _e('发起'); ?></h2>
						<?php else:?>
						<li class="active"><a href="javascript::void(0);"><?php _e('悬赏'); ?></a></li>
						<?php endif;?>
					</ul>
					<!-- end tab 切换 -->
					<form action="publish/ajax/<?php if ($this->question_info['question_id']) { ?>modify<?php } else { ?>publish<?php } ?>_question/" method="post" id="question_form" onsubmit="return false;">
						<input type="hidden" name="post_hash" value="<?php echo new_post_hash(); ?>" />
						<input type="hidden" name="attach_access_key" value="<?php echo $this->attach_access_key; ?>" />
						<input type="hidden" name="question_id" id="question_id" value="<?php echo $this->question_info['question_id']; ?>" />
						<input type="hidden" name="ask_user_id" value="<?php echo $_POST['ask_user_id']; ?>" />
						<input type="hidden" name="ssid" value="<?php echo $this->ssid;?>" />
						<?php if ($this->question_category_list) { ?>
						<select name="category_id" class="collapse" id="category_id">
							<option value="0">- <?php _e('请选择分类'); ?> -</option>
							<?php echo $this->question_category_list; ?>
						</select>
						<?php } ?>
						<div class="aw-mod aw-mod-publish">
							<div class="mod-body">
								<h3><?php _e('问题标题'); ?>:</h3>
								<!-- 问题标题 -->
								<div class="aw-publish-title<?php if (!$this->question_category_list) { ?> active<?php } ?>">
									<div>
										<?php if(!$this->question_info['question_content']){ ?>
										<label class="oldPwdTip question_contents-label" onclick="$(this).hide();$('#question_contents').focus();"><?php _e('问题标题'); ?>...</label>
										<?php } ?>
										<input type="text" name="question_content" id="question_contents" value="<?php echo $this->question_info['question_content']; ?>" class="form-control" onfocus="hideOldPwdTip('question_contents');" onblur="toggleOldPwdTip('question_contents',this.value);"/>
										<div class="aw-publish-suggest-question collapse">
											<p class="text-color-999">你的问题可能已经有答案</p>
											<ul class="aw-dropdown-list">
											</ul>
										</div>
									</div>
									<?php if ($this->question_category_list) { ?>
									<div class="dropdown category">
										<div class="dropdown-toggle" data-toggle="dropdown">
											<span id="aw-topic-tags-select" class="aw-hide-txt"><?php _e('选择分类'); ?></span>
											<a href="javascript:;"><i class="icon icon-down"></i></a>
										</div>
									</div>
									<?php } ?>
								</div>
								<!-- end 问题标题 -->
								<h3><?php _e('问题补充 (选填)'); ?>:</h3>
								<div class="aw-mod aw-editor-box">
									<div class="mod-head">
										<div class="wmd-panel">
										<?php  if(get_hook_config('editor')['type']['value']=='ueditor'):?>	
								        <script id="wmd-input" name="question_detail" type="text/plain"><?php echo $this->question_info['question_detail']; ?></script>
										<?php  elseif(get_hook_config('editor')['type']['value']=='ckeditor'):?>	
								        <textarea class="wmd-input form-control autosize editor" id="wmd-input" rows="15" name="question_detail"><?php echo $this->question_info['question_detail']; ?></textarea>
								        <?php else:?>
											<textarea style="display: none;" id="wangcontent" rows="15" name="question_detail"><?php echo $this->question_info['question_detail']; ?></textarea>
											<div id="wmd-input">

											</div>
								        <?php endif;?>
								        </div>
									</div>
									<div class="mod-body">
										<span class="pull-right text-color-999" id="question_detail_message">&nbsp;</span>
									</div>
								</div>
								<?php if (!$this->question_info['question_id']) { ?>
								<h3><?php _e('添加话题'); ?>:</h3>
								<div class="aw-topic-bar" data-type="publish">
									<div class="tag-bar clearfix">
										<?php if ($_GET['topic_title']) { ?>
										<span class="topic-tag">
											<a class="text"><?php echo urldecode($_GET['topic_title']); ?></a>
											<a class="close" onclick="$(this).parents('.topic-tag').remove();">
												<i class="icon icon-delete"></i>
											</a>
											<input type="hidden" value="<?php echo urldecode($_GET['topic_title']); ?>" name="topics[]" />
										</span>
										<?php } ?>

										<?php if ($_POST['topics']) { ?>
										<?php foreach ($_POST['topics'] AS $key => $val) { ?>
										<span class="topic-tag">
											<a class="text"><?php echo $val; ?></a>
											<input type="hidden" value="<?php echo $val; ?>" name="topics[]" />
										</span>
										<?php } ?>
										<?php } ?>

										<span class="aw-edit-topic icon-inverse"><i class="icon icon-edit"></i> <?php _e('编辑话题'); ?></span>
										</span>
									</div>
								</div>
								<?php if ($this->recent_topics) { ?>
								<h3><?php _e('最近话题'); ?>:</h3>
								<div class="aw-topic-bar">
									<div class="topic-bar clearfix">
										<?php foreach($this->recent_topics as $key => $val) { ?>
										<span class="topic-tag" onclick="$('#aw_edit_topic_title').val('<?php echo $val; ?>');$('.add').click();$(this).hide();">
											<a class="text">
												<?php echo $val; ?>
											</a>
										</span>
										<?php } ?>
									</div>
								</div>
								<?php } ?>
								<?php } ?>
								<?php if (!$this->question_info['question_id'] AND $this->category_reward == 'reward') { ?>
								<div class="trem_show">
									<h3><?php _e('到期时间'); ?>:</h3>
									<div class="aw-topic-bar" data-type="publish">
										<div class="tag-bar clearfix">
											<input type="text" class="form-control mod-data date-start" id="reward_time" name="reward_time" autocomplete="off" placeholder="选择到期时间" style="width: 250px !important;" readonly value='<?php echo date("Y-m-d",strtotime("+".(get_setting("longest_period")-1)." day"));?>'>
										</div>
									</div>
								</div>
								<input type="hidden" value="1" name="is_pay" id="is_pay"/>
								<?php } ?>

								<?php if ($this->human_valid) { ?>
								<div class="aw-auth-img clearfix">
									<div class="embed-captcha pull-right" style="width:260px"></div>
                                    <p class="wait pull-right">正在加载验证码......</p>
									<!-- <input class="form-control pull-right" type="text" name="seccode_verify" placeholder="验证码" />
									<em class="auth-img pull-right"><img src="" onclick="this.src = G_BASE_URL + '/account/captcha/' + Math.floor(Math.random() * 10000);" id="captcha"  /></em> -->
								</div>
								<?php } ?>
							</div>
							<div class="mod-footer clearfix">
								<?php if (get_setting('integral_system_enabled') == 'Y') { ?><a href="integral/rule/" target="_blank">[<?php _e('积分规则'); ?>]</a><?php } ?>
								<span class="aw-anonymity">
									<?php if ($this->question_info['question_id'] AND ($this->user_info['permission']['is_administortar'] OR $this->user_info['permission']['is_moderator'])) { ?>
									<label><input type="checkbox" class="pull-left" value="1" name="do_delete" />
										<?php _e('删除问题'); ?></label>
									<?php } ?>
									<?php if (!$this->question_info['question_id'] AND get_setting('anonymous_enable') == 'Y') { ?>
									<label><input type="checkbox" class="pull-left" value="1" name="anonymous" />
										<?php _e('匿名'); ?></label>
									<?php } ?>
									<?php if(get_setting('draft_enabled')=='Y'){ ?>
                                        <a id="saveDraft" data-type="question"><?php _e('保存草稿'); ?></a>
                                    <?php } ?>
								</span>
								<a class="btn btn-large btn-success btn-publish-submit" id="publish_submit" <?php if (!$this->human_valid) { ?>onclick="AWS.ajax_post($('#question_form'),AWS.ajax_processer, 'publish_question'); return false;"<?php } ?>><?php _e('确认发起'); ?></a>
								
							</div>
						</div>
					</form>
				</div>
				<!-- 侧边栏 -->
				<div class="col-sm-12 col-md-3 aw-side-bar hidden-xs">
					<!-- 问题发起指南 -->
					<div class="aw-mod publish-help">
						<div class="mod-head">
						<?php if($_GET['category']):?>
							<h3><?php _e('悬赏的发起指南'); ?></h3>
					<?php else:?>
							<h3><?php _e('问题发起指南'); ?></h3>
					<?php endif;?>
						</div>
						<?php if(!$_GET['category']):?>
						<div class="mod-body">
							<p><b>• <?php _e('问题标题'); ?>:</b> <?php _e('请用准确的语言描述您发布的问题思想'); ?></p>
							<p><b>• <?php _e('问题补充'); ?>:</b> <?php _e('详细补充您的问题内容, 并提供一些相关的素材以供参与者更多的了解您所要问题的主题思想'); ?></p>
							<p><b>• <?php _e('选择话题'); ?>:</b> <?php _e('选择一个或者多个合适的话题, 让您发布的问题得到更多有相同兴趣的人参与. 所有人可以在您发布问题之后添加和编辑该问题所属的话题'); ?></p>
							<?php if (get_setting('integral_system_enabled') == 'Y') { ?>
							<p><b>• <?php _e('关于积分'); ?>：</b> <?php _e('发起一个问题会消耗您 %s 个积分', -get_setting('integral_system_config_new_question')); ?>, <?php if (get_setting('integral_system_config_answer_change_source') == 'Y') { _e('每多一个回复你将获得 %s 个积分的奖励', -get_setting('integral_system_config_new_answer')); ?> ,<?php } _e('为了您的利益, 在发起问题的时候希望能够更好的描述您的问题以及多使用站内搜索功能'); ?>.</p>
							<?php } ?>
						</div>
					<?php else:?>
						<div class="mod-body">
							<p><b>• <?php _e('悬赏期限'); ?>:</b> <?php _e('系统允许的最长悬赏期是'.get_setting('longest_period').'天，可选择在此之前的到期日。悬赏期之内的回答才有可能参与奖金分配'); ?></p>
							<p><b>• <?php _e('悬赏金额'); ?>:</b> <?php _e(' 系统并没有限制悬赏的金额，您可以自由选择，理论上，悬赏额越多时问答的人越积极'); ?></p>
							<p><b>• <?php _e('赏金分配'); ?>:</b> <?php _e('悬赏期内无人回答，则悬赏金退回您的余额，问题转为普通问答；有人作答至悬赏期结束后24小时，您可以自己选择最佳回复，最多可选择三个；该期间内未选择，则交由网站运营者选择最佳回复；运营者仍未选择最佳回复时，由系统根据票数自动选择前三名作为最佳回复；最佳回复设置后，进入公示期'.get_setting('publicity').'天，有异议由网站运营者裁定；公示期结束或者运营者裁定后，赏金平分给最佳回复的贡献者'); ?></p>
						</div>
					<?php endif;?>
					</div>
					<!-- end 问题发起指南 -->
				</div>
				<!-- end 侧边栏 -->
			</div>
		</div>
	</div>
</div>
<?php 
hook('editor','init',['name'=>'wmd-input','cat'=>'question']);
?>
<script type="text/javascript">
var pay_data={
            'url':G_BASE_URL+'/explore/doact/?p=reward&a=add_finance',
            'notify_url':G_BASE_URL+'/pay/finance_notify/'
        };
	var ATTACH_ACCESS_KEY = '<?php echo $this->attach_access_key; ?>';
	var CATEGORY_ID = <?php echo $this->question_info['category_id']; ?>;
	var PUBLISH_TYPE = 'question';
	var editor_type="<?php echo get_hook_config('editor')['type']['value'];?>"
	//执行一个laydate实例
	laydate.render({
	  	elem: '#reward_time', //指定元素
	  	min: '<?php echo date("Y-m-d");?>',
	  	max: '<?php echo date("Y-m-d",strtotime("+".(get_setting("longest_period")-1)." day"));?>'
	});
	function suok(){
		$('#question_form').ajaxSubmit(
		{
			dataType: 'json',
			success: function (result)
			{
				console.log(result);
				if(result.errno == 999){
					pay_data.question_id=result.err.question_id;
					pay_data.reward_time=result.err.reward_time;
					showpay();
				}else if(result.errno == 1){
					location.href=result.rsm.url;
				}else{
					layer.msg(result.err);
				}
			}
		});
	}
	<?php if ($this->human_valid) { ?>
        var handlerEmbed = function (captchaObj) {
            $('#publish_submit').click(function(){
                var validate = captchaObj.getValidate();
                if (!validate) {
                    AWS.alert("请先完成验证");
                    return false;
                } else{
                    AWS.ajax_post($('#question_form'),AWS.ajax_processer, 'publish_question');
                    captchaObj.reset(); // 调用该接口进行重置 
                    return false;
                }
            });
            // 将验证码加到id为captcha的元素里，同时会有三个input的值：geetest_challenge, geetest_validate, geetest_seccode
            captchaObj.appendTo(".embed-captcha");
            captchaObj.onReady(function () {
                $(".wait").css('display','none');
            });
        };

        $.ajax({
            // 获取id，challenge，success（是否启用failback）
            url: G_BASE_URL+ "/account/slide_captcha/?t=" + (new Date()).getTime()+"&client_type='web'", // 加随机数防止缓存
            type: "get",
            dataType: "json",
            success: function (data) {
                var dataObj = eval('(' + data.rsm + ')');
                // 使用initGeetest接口
                // 参数1：配置参数
                // 参数2：回调，回调的第一个参数验证码对象，之后可以使用它做appendTo之类的事件
                initGeetest({
                    gt: dataObj.gt,
                    challenge: dataObj.challenge,
                    new_captcha: dataObj.new_captcha,
                    offline: !dataObj.success, // 表示用户后台检测极验服务器是否宕机，一般不需要关注
                    product: "embed", // 产品形式，包括：float，embed，popup。注意只对PC版验证码有效
                    width: '100%' // 设置按钮宽度, 与父元素宽度一致
                }, handlerEmbed);
            }
        });
    <?php } ?>
</script>

<?php TPL::output('global/footer.tpl.htm'); ?>